<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入vue库 -->
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        商品价格：
        <input type="text" v-model="price">
        <br><br>
        商品数量：
        <button @click="add">+</button>
        <span>{{num}}</span>
        <button @click="sub">-</button>
        <hr>
        <div>总价：{{total}}</div>
    </div>

    <script>
        // 1、创建vue对象
        const appCom = {
            data() {
                return {
                    num: 1,
                    price: 100,
                }
            },
            methods: {
                add() {
                    this.num++;
                },
                sub() {
                    if(this.num == 1){
                        alert("不能再减了");
                        return;
                    }
                    this.num--;
                }
            },
            computed: {
                total() {
                    return this.num * this.price;
                }
            }
        };
        Vue.createApp(appCom).mount("#app");
    </script>
</body>
</html>